package com.cskaoyan.shopping.controller;

import com.cskaoyan.mall.commons.result.ResponseData;
import com.cskaoyan.mall.commons.result.ResponseUtil;
import com.cskaoyan.mall.constant.ShoppingRetCode;
import com.cskaoyan.mall.dto.ProductDetailRequest;
import com.cskaoyan.mall.dto.ProductDetailResponse;
import com.cskaoyan.shopping.service.IProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName: ProductDetailController
 * @Description:
 * @Author: 你猜
 * @Date: 2022/6/17 20:20
 */

@RestController
public class ProductDetailController {

    @Autowired
    IProductService productService;

    // http://124.71.209.81/shopping/product/100047001
    @GetMapping("/shopping/product/{id}")
    public ResponseData getProductDetail(@PathVariable Long id) {
        ProductDetailRequest productDetailRequest = new ProductDetailRequest();
        productDetailRequest.setId(id);

        ProductDetailResponse productDetailResponse = productService.getProductDetail(productDetailRequest);

        if (ShoppingRetCode.SUCCESS.getCode().equals(productDetailResponse.getCode())) {
            return new ResponseUtil().setData(productDetailResponse.getProductDetailDto());
        }
        return new ResponseUtil().setErrorMsg(productDetailResponse.getMsg());
    }
}